<?php
class ActionsDetector
{
	protected $_action;
	public function ActionsDetector($dir,$controllers=array())
	{
		$pattern  = "#public([ ]+)\function\([ ]+)[a-z.-]+\.[a-z]{2,4}/#";
		$caractersToReplace=array('A','B','C','D','E','F','G','H','I','J','k','L','M','N','O','P','Q','R',
								'S','T','U','V','W','X','Y','Z');
		$actionsList = array();
		foreach($controllers as $key => $val) {
			$contents =file_get_contents($dir."/".$val);
			if(preg_match_all("/public[ ]+function[ ]+([a-z-A-Z-0-9-]+)Action[ ]*\(/", $contents, $matches)) {
				$controllerName = substr($val,1,-14);
				$controllerFirstLetter = substr($val,0,1);
				
				foreach($caractersToReplace as $key => $val) {
						$controllerName = str_replace($val,"-".strtolower($val),$controllerName);						
				}
				$controllerName = strtolower($controllerFirstLetter).$controllerName;
				
				$actions = $matches[1];
				if(is_array($actions))
				foreach($actions as $action) {
					foreach($caractersToReplace as $key => $val) {
						$action = str_replace($val,"-".strtolower($val),$action);						
					}
					$actionsList[$controllerName][] = $action;
				}
			} 
		}
		
		$this->_action = $actionsList;
		
		//print_r($actionsList); exit;
	}
	
	public function getActions()
	{
		return $this->_action;
	}
}